CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3)

PROJECT(tulip)

#SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})

IF(MSVC)
	SET(VC_WARNINGS "/wd4819 /wd4018 /wd4996")
	SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${VC_WARNINGS}")
	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${VC_WARNINGS}")
	ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS")
	
	#如果要静态链接运行时(c++ runtime),打开下面的4个注释
	#但这样会导致链接错误(因为多个库都将c++运行时静态链接进去了,导致obj符号冲突)
	#原因:可能是crt中的string、stream等涉及到操作系统资源切换的东西无法同时公用吧???(猜测多半是错误的)
	#SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
	#SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
	#SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
	#SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
ENDIF()

#macosx10.10.1下编译问题比较诡异
#用命令行编译没有问题,但用xcode就莫名其妙的link error(全都是关于stl的错误)
IF(APPLE)
	SET(CMAKE_MACOSX_RPATH 1)
    #SET(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -stdlib=libstdc++")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
ENDIF()

IF(UNIX)
	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
ENDIF()

## ========================================================
## Operating system preprocessor macros
## ========================================================
IF(LINUX)
  ADD_DEFINITIONS("-D_LINUX")
ENDIF(LINUX)
IF(WIN32)
  ADD_DEFINITIONS("-D_WIN32")
ENDIF(WIN32)
IF(APPLE)
  ADD_DEFINITIONS("-D__APPLE__")
ENDIF(APPLE)

## ========================================================
## Tulip version variables
## ========================================================
SET(TulipMajorVersion 4)
SET(TulipMinorVersion 6)
SET(TulipReleaseVersion 1)
SET(TulipVersionSeparator .)
IF(MSVC) #specific options for Visual Studio
  SET(TulipVersionSeparator _)
ENDIF()
SET(TulipVersion "${TulipMajorVersion}${TulipVersionSeparator}${TulipMinorVersion}${TulipVersionSeparator}${TulipReleaseVersion}")
SET(TulipMMVersion "${TulipMajorVersion}${TulipVersionSeparator}${TulipMinorVersion}")
SET(TulipIntVersion "${TulipMajorVersion}${TulipMinorVersion}${TulipReleaseVersion}")

#CONFIGURE_FILE("library/tulip-core/include/tulip/TulipRelease.h.in" "library/tulip-core/include/tulip/TulipRelease.h")

#tulip项目根目录
SET(TULIP_ROOT_DIR ${CMAKE_SOURCE_DIR})
#tulip所有子项目的输出路径
SET(TULIP_OUTPUT_DIR "${CMAKE_BINARY_DIR}/bin")

#第3方库目录
SET(TULIP_THIRD_PARTY_DIR ${TULIP_ROOT_DIR}/thirdparty)
#核心库的目录
SET(TULIP_LIBRARY_DIR ${TULIP_ROOT_DIR}/library)
#插件的目录
SET(TULIP_PLUGIN_DIR ${TULIP_ROOT_DIR}/plugins)

SET(ZLibInclude ${TULIP_THIRD_PARTY_DIR})
SET(GZStreamInclude ${TULIP_THIRD_PARTY_DIR})
SET(QHULLInclude ${TULIP_THIRD_PARTY_DIR})
SET(UTF8CppInclude ${TULIP_THIRD_PARTY_DIR}/utf8-cpp/source)
SET(YAJLInclude ${TULIP_THIRD_PARTY_DIR}/yajl/src)
SET(OGDFInclude ${TULIP_THIRD_PARTY_DIR}/OGDF)

SET(GZStreamLibrary gzstream)
SET(ZLibLibrary zlib)
SET(OGDFLibrary ogdf)
SET(QHULLLibrary qhull)
SET(YajlLibrary yajl)

SET(TulipCoreInclude ${TULIP_LIBRARY_DIR}/tulip-core)
SET(TulipOGDFInclude ${TULIP_LIBRARY_DIR}/tulip-ogdf)
#下面三个变量从tulip移植过来,暂时还没有用到
SET(TulipOGLInclude ${TULIP_LIBRARY_DIR}/tulip-ogl)
SET(TulipGUIInclude ${TULIP_LIBRARY_DIR}/tulip-gui)
SET(TulipPythonInclude ${TULIP_LIBRARY_DIR}/tulip-python)

## ========================================================
## Tulip libraries names
## ========================================================
SET(LibTulipCoreName "tulip-core")
SET(LibTulipOGDFName "tulip-ogdf")
#下面三个变量从tulip移植过来,暂时还没有用到
SET(LibTulipOglName "tulip-ogl")
SET(LibTulipGUIName "tulip-gui")
SET(LibTulipPythonName "tulip-python")

#SET(TulipLibs ${LibTulipCoreName} ${LibTulipOglName} ${LibTulipGUIName} ${LibTulipOGDFName})
SET(TulipLibs ${LibTulipCoreName} ${LibTulipOGDFName})

#SET(BUILD_ZLIB_SHARED      ON CACHE BOOL "Build zlib shared library? [ON|OFF]")
#SET(BUILD_GZSTREAM_SHARED  ON CACHE BOOL "Build gzstream shared library? [ON|OFF]")
#SET(BUILD_OGDF_SHARED      ON CACHE BOOL "Build ogdf shared library? [ON|OFF]")

SET(BUILD_TULIP_SHARED     ON CACHE BOOL "Build tulip shared library? [ON|OFF]")
SET(BUILD_CORE_ONLY        ON CACHE BOOL "Do you want a minimal build of Tulip ? [ON|OFF]")

IF(BUILD_TULIP_SHARED)
  SET(BUILD_ZLIB_SHARED      ON)
  SET(BUILD_GZSTREAM_SHARED  ON)
  SET(BUILD_YAJL_SHARED      ON)
  SET(BUILD_OGDF_SHARED      ON)
ENDIF()

ADD_SUBDIRECTORY(thirdparty)
ADD_SUBDIRECTORY(library)
ADD_SUBDIRECTORY(plugins)
ADD_SUBDIRECTORY(test)